<!DOCTYPE html>
<html lang="en">
  <head>
    <title>Protocols  Reference</title>
    <link rel="stylesheet" type="text/css" href="css/jazzy.css" />
    <link rel="stylesheet" type="text/css" href="css/highlight.css" />
    <meta charset="utf-8">
    <script src="js/jquery.min.js" defer></script>
    <script src="js/jazzy.js" defer></script>
    
    <script src="js/lunr.min.js" defer></script>
    <script src="js/typeahead.jquery.js" defer></script>
    <script src="js/jazzy.search.js" defer></script>
  </head>
  <body>

    <a name="//apple_ref/swift/Section/Protocols" class="dashAnchor"></a>

    <a title="Protocols  Reference"></a>

    <header class="header">
      <p class="header-col header-col--primary">
        <a class="header-link" href="index.html">
          KituraContracts 1.2.200 Docs
        </a>
         (99% documented)
      </p>
    
      <p class="header-col--secondary">
        <form role="search" action="search.json">
          <input type="text" placeholder="Search documentation" data-typeahead>
        </form>
      </p>
    
        <p class="header-col header-col--secondary">
          <a class="header-link" href="https://github.com/Kitura/KituraContracts/">
            <img class="header-icon" src="img/gh.png"/>
            View on GitHub
          </a>
        </p>
    
    </header>

    <p class="breadcrumbs">
      <a class="breadcrumb" href="index.html">KituraContracts Reference</a>
      <img class="carat" src="img/carat.png" />
      Protocols  Reference
    </p>

    <div class="content-wrapper">
      <nav class="navigation">
        <ul class="nav-groups">
          <li class="nav-group-name">
            <a class="nav-group-name-link" href="Classes.html">Classes</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Classes/Coder.html">Coder</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Classes/QueryDecoder.html">QueryDecoder</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Classes/QueryEncoder.html">QueryEncoder</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a class="nav-group-name-link" href="Enums.html">Enumerations</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Enums/IdentifierError.html">IdentifierError</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Enums/Operator.html">Operator</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Enums/Order.html">Order</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Enums/QueryParamsError.html">QueryParamsError</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a class="nav-group-name-link" href="Extensions.html">Extensions</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Extensions/Bool.html">Bool</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Extensions/Double.html">Double</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Extensions/Float.html">Float</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Extensions/Int.html">Int</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Extensions/Int16.html">Int16</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Extensions/Int32.html">Int32</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Extensions/Int64.html">Int64</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Extensions/Int8.html">Int8</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Extensions.html#/s:10Foundation11JSONDecoderC">JSONDecoder</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Extensions.html#/s:10Foundation11JSONEncoderC">JSONEncoder</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Extensions/String.html">String</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Extensions/UInt.html">UInt</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Extensions/UInt16.html">UInt16</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Extensions/UInt32.html">UInt32</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Extensions/UInt64.html">UInt64</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Extensions/UInt8.html">UInt8</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Extensions/UUID.html">UUID</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a class="nav-group-name-link" href="Protocols.html">Protocols</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Protocols/BodyDecoder.html">BodyDecoder</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Protocols/BodyEncoder.html">BodyEncoder</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Protocols/Identifier.html">Identifier</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Protocols/Operation.html">Operation</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Protocols/QueryParams.html">QueryParams</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a class="nav-group-name-link" href="Structs.html">Structures</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Structs/BodyFormat.html">BodyFormat</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Structs/ExclusiveRange.html">ExclusiveRange</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Structs/GreaterThan.html">GreaterThan</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Structs/GreaterThanOrEqual.html">GreaterThanOrEqual</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Structs/InclusiveRange.html">InclusiveRange</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Structs/LowerThan.html">LowerThan</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Structs/LowerThanOrEqual.html">LowerThanOrEqual</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Structs/Ordering.html">Ordering</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Structs/Pagination.html">Pagination</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Structs/RequestError.html">RequestError</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Structs/RequestError/ErrorBody.html">– ErrorBody</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Structs/UnsupportedBodyFormatError.html">UnsupportedBodyFormatError</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a class="nav-group-name-link" href="Typealiases.html">Type Aliases</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Typealiases.html#/s:15KituraContracts19CodableArrayClosurea">CodableArrayClosure</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Typealiases.html#/s:15KituraContracts25CodableArrayResultClosurea">CodableArrayResultClosure</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Typealiases.html#/s:15KituraContracts14CodableClosurea">CodableClosure</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Typealiases.html#/s:15KituraContracts24CodableIdentifierClosurea">CodableIdentifierClosure</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Typealiases.html#/s:15KituraContracts20CodableResultClosurea">CodableResultClosure</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Typealiases.html#/s:15KituraContracts29IdentifierCodableArrayClosurea">IdentifierCodableArrayClosure</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Typealiases.html#/s:15KituraContracts35IdentifierCodableArrayResultClosurea">IdentifierCodableArrayResultClosure</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Typealiases.html#/s:15KituraContracts24IdentifierCodableClosurea">IdentifierCodableClosure</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Typealiases.html#/s:15KituraContracts30IdentifierCodableResultClosurea">IdentifierCodableResultClosure</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Typealiases.html#/s:15KituraContracts27IdentifierNonCodableClosurea">IdentifierNonCodableClosure</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Typealiases.html#/s:15KituraContracts30IdentifierSimpleCodableClosurea">IdentifierSimpleCodableClosure</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Typealiases.html#/s:15KituraContracts17NonCodableClosurea">NonCodableClosure</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Typealiases.html#/s:15KituraContracts13ResultClosurea">ResultClosure</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Typealiases.html#/s:15KituraContracts20SimpleCodableClosurea">SimpleCodableClosure</a>
              </li>
            </ul>
          </li>
        </ul>
      </nav>
      <article class="main-content">

        <section class="section">
          <div class="section-content top-matter">
            <h1>Protocols</h1>
            <p>The following protocols are available globally.</p>

          </div>
        </section>

        <section class="section">
          <div class="section-content">
            <div class="task-group">
              <ul class="item-container">
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:15KituraContracts11BodyDecoderP"></a>
                    <a name="//apple_ref/swift/Protocol/BodyDecoder" class="dashAnchor"></a>
                    <a class="token" href="#/s:15KituraContracts11BodyDecoderP">BodyDecoder</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>A class that conforms to <code>BodyDecoder</code> must be able to decode from <code>Data</code> into a <code>Codable</code> type.
This class can then be used to produce input objects for a Codable route.</p>

                        <a href="Protocols/BodyDecoder.html" class="slightly-smaller">See more</a>
                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">protocol</span> <span class="kt">BodyDecoder</span> <span class="p">:</span> <span class="kt">AnyObject</span></code></pre>

                        </div>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:15KituraContracts11BodyEncoderP"></a>
                    <a name="//apple_ref/swift/Protocol/BodyEncoder" class="dashAnchor"></a>
                    <a class="token" href="#/s:15KituraContracts11BodyEncoderP">BodyEncoder</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>A class that conforms to <code>BodyEncoder</code> must be able to encode a <code>Codable</code> type into <code>Data</code>.
This class can then be used to produce output objects for a Codable route.</p>

                        <a href="Protocols/BodyEncoder.html" class="slightly-smaller">See more</a>
                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">protocol</span> <span class="kt">BodyEncoder</span> <span class="p">:</span> <span class="kt">AnyObject</span></code></pre>

                        </div>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:15KituraContracts11QueryParamsP"></a>
                    <a name="//apple_ref/swift/Protocol/QueryParams" class="dashAnchor"></a>
                    <a class="token" href="#/s:15KituraContracts11QueryParamsP">QueryParams</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>An object that conforms to QueryParams is identified as being decodable from URLEncoded data.
This can be applied to a Codable route to define the names and types of the expected query parameters, and provide type-safe access to their values. The <code><a href="Classes/QueryDecoder.html">QueryDecoder</a></code> is used to decode the URL encoded parameters into an instance of the conforming type.</p>
<h3 id='usage-example' class='heading'>Usage Example:</h3>
<pre class="highlight swift"><code><span class="kd">struct</span> <span class="kt">Query</span><span class="p">:</span> <span class="kt">QueryParams</span> <span class="p">{</span>
   <span class="k">let</span> <span class="nv">id</span><span class="p">:</span> <span class="kt">Int</span>
<span class="p">}</span>
<span class="n">router</span><span class="o">.</span><span class="nf">get</span><span class="p">(</span><span class="s">"/user"</span><span class="p">)</span> <span class="p">{</span> <span class="p">(</span><span class="nv">query</span><span class="p">:</span> <span class="kt">Query</span><span class="p">,</span> <span class="nv">respondWith</span><span class="p">:</span> <span class="p">(</span><span class="kt">User</span><span class="p">?,</span> <span class="kt">RequestError</span><span class="p">?)</span> <span class="o">-&gt;</span> <span class="kt">Void</span><span class="p">)</span> <span class="k">in</span>
    <span class="k">guard</span> <span class="k">let</span> <span class="nv">user</span><span class="p">:</span> <span class="kt">User</span> <span class="o">=</span> <span class="n">userArray</span><span class="p">[</span><span class="n">query</span><span class="o">.</span><span class="n">id</span><span class="p">]</span> <span class="k">else</span> <span class="p">{</span>
       <span class="k">return</span> <span class="nf">respondWith</span><span class="p">(</span><span class="kc">nil</span><span class="p">,</span> <span class="o">.</span><span class="n">notFound</span><span class="p">)</span>
    <span class="p">}</span>
    <span class="nf">respondWith</span><span class="p">(</span><span class="n">user</span><span class="p">,</span> <span class="kc">nil</span><span class="p">)</span>
<span class="p">}</span>
</code></pre>
<h3 id='decoding-empty-values' class='heading'>Decoding Empty Values:</h3>

<p>When an HTML form is sent with an empty or unchecked field, the corresponding key/value pair is sent with an empty value (i.e. <code>&amp;key1=&amp;key2=</code>).
The corresponding mapping to Swift types performed by <code><a href="Classes/QueryDecoder.html">QueryDecoder</a></code> is as follows:</p>

<ul>
<li>Any Optional type (including <code>String?</code>) defaults to <code>nil</code></li>
<li>Non-optional <code>String</code> successfully decodes to <code>&quot;&quot;</code></li>
<li>Non-optional <code>Bool</code> decodes to <code>false</code></li>
<li>All other non-optional types throw a decoding error</li>
</ul>

                        <a href="Protocols/QueryParams.html" class="slightly-smaller">See more</a>
                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">protocol</span> <span class="kt">QueryParams</span> <span class="p">:</span> <span class="kt">Decodable</span><span class="p">,</span> <span class="kt">Encodable</span></code></pre>

                        </div>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:15KituraContracts10IdentifierP"></a>
                    <a name="//apple_ref/swift/Protocol/Identifier" class="dashAnchor"></a>
                    <a class="token" href="#/s:15KituraContracts10IdentifierP">Identifier</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>An identifier for an entity with a string representation.</p>
<h3 id='usage-example' class='heading'>Usage Example:</h3>
<pre class="highlight swift"><code> <span class="c1">// Used in the Id field.</span>
 <span class="kd">public</span> <span class="kd">typealias</span> <span class="kt">IdentifierCodableClosure</span><span class="o">&lt;</span><span class="kt">Id</span><span class="p">:</span> <span class="kt">Identifier</span><span class="p">,</span> <span class="kt">I</span><span class="p">:</span> <span class="kt">Codable</span><span class="p">,</span> <span class="kt">O</span><span class="p">:</span> <span class="kt">Codable</span><span class="o">&gt;</span> <span class="o">=</span> <span class="p">(</span><span class="kt">Id</span><span class="p">,</span> <span class="kt">I</span><span class="p">,</span> <span class="kd">@escaping</span> <span class="kt">CodableResultClosure</span><span class="o">&lt;</span><span class="kt">O</span><span class="o">&gt;</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kt">Void</span>
</code></pre>

                        <a href="Protocols/Identifier.html" class="slightly-smaller">See more</a>
                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">protocol</span> <span class="kt">Identifier</span> <span class="p">:</span> <span class="kt">Decodable</span><span class="p">,</span> <span class="kt">Encodable</span></code></pre>

                        </div>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:15KituraContracts9OperationP"></a>
                    <a name="//apple_ref/swift/Protocol/Operation" class="dashAnchor"></a>
                    <a class="token" href="#/s:15KituraContracts9OperationP">Operation</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>An identifier for an operation object.</p>

                        <a href="Protocols/Operation.html" class="slightly-smaller">See more</a>
                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">protocol</span> <span class="kt">Operation</span> <span class="p">:</span> <span class="kt">Decodable</span><span class="p">,</span> <span class="kt">Encodable</span></code></pre>

                        </div>
                      </div>
                    </section>
                  </div>
                </li>
              </ul>
            </div>
          </div>
        </section>

      </article>
    </div>
    <section class="footer">
      <p>&copy; 2020 <a class="link" href="https://github.com/Kitura/KituraContracts" target="_blank" rel="external">IBM and Kitura project authors</a>. All rights reserved. (Last updated: 2020-12-09)</p>
      <p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.13.6</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
    </section>
  </body>
</div>
</html>
